package com.li.core.controller;

import com.alibaba.fastjson.JSONObject;
import com.li.configserve.config.globalexception.MyException;
import com.li.configserve.config.globalexception.NotFountResourceException;
import com.li.configserve.domain.gloabreturn.ResponseInfo;
import com.li.core.feginclient.OsBackFeginClient;
import com.li.toolkit.constant.NumConst;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

/**
 * @description:
 * @author: Lidong
 * @time: 2020/6/28 22:18
 **/
@RestController
@RequestMapping("/test")
public class TestCoreController {

    private static final Logger logger = LoggerFactory.getLogger(TestCoreController.class);

    @Autowired
    OsBackFeginClient feginClientTest;

    /**
     * 正常接口
     */
    @GetMapping("/normal")
    public ResponseInfo normal() {
        String data = "模拟的响应数据";
        ResponseInfo responseInfo = new ResponseInfo();
        responseInfo.setCode(200);
        responseInfo.setMessage("请求成功");
        responseInfo.setData(new ArrayList<>());
        return responseInfo;
    }

    /**
     * 抛出自定义不能发行资源异常，测试自定义无法发现资源异常处理器
     */
    @GetMapping("/rsexception")
    public String createException() throws NotFountResourceException {
        throw new NotFountResourceException("NullPointerException 空指针异常信息");
    }

    /**
     * 抛出自定义异常，测试自定义异常处理器
     */
    @GetMapping("/myexception")
    public String createMyException() throws MyException {
        throw new MyException("MyException 自定义异常信息");
    }

    /**
     * 抛出空指针异常，测试全局异常处理器
     */
    @GetMapping("/exception")
    public String createGlobleException() {
        throw new NullPointerException("NullPointerException 空指针异常信息");
    }


    @RequestMapping("/test1")
    public String test1(@RequestBody Map<String,String> map){
        return map.getOrDefault("tagid","");
    }

    @RequestMapping("/test2")
    public Map<String,String> test2(){
        Map<String,String> map=new HashMap<>(NumConst.MAP_SIZE);
        map.put("test1","test");
        map.put("test2","test2");
        Map<String, String> test = feginClientTest.getTest(map);
        logger.info(JSONObject.toJSONString(test));
        return map;
    }

    @RequestMapping("/test3")
    public void test3(){
        logger.info("test4");
    }

}
